package info.cs52.fes.dao;

import info.cs52.fes.Application;
import info.cs52.fes.data.Meal;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

public class MealDAO {

	public static Meal find(String id) {
		EntityManager em = Application.getEntityManager();
		return em.find(Meal.class, id);
	}

	public static void persist(Meal meal) {
		EntityManager em = Application.getEntityManager();
		EntityTransaction tr = em.getTransaction();
		tr.begin();
		em.persist(meal);
		tr.commit();
	}

	public static void delete(String id) {
		EntityManager em = Application.getEntityManager();
		EntityTransaction tr = em.getTransaction();
		tr.begin();
		em.remove(em.getReference(Meal.class, id)); 
		tr.commit();
	}

}
